package servlet;
import hbase.HbaseUtil;
import hbase.Student;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.ArrayList;

/**
 * @author Lu Ruotong
 * @date 2022/3/12 10:16
 */

@WebServlet("/studentAdd")
public class HBaseAdd extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        String StudentId = req.getParameter("StudentId");
        String name = req.getParameter("name");
        String date_ruxue = req.getParameter("date_ruxue");
        String telephone = req.getParameter("telephone");
        String semester = req.getParameter("semester");
        String StudentStatus = req.getParameter("StudentStatus");


        ArrayList<Student> studentArrayList = new ArrayList<>();
        Student st = new Student();
        st.setStudentId(StudentId);
        st.setName(name);
        st.setDate_ruxue(date_ruxue);
        st.setTelephone(telephone);
        st.setSemester(semester);
        st.setStudentStatus(StudentStatus);
        studentArrayList.add(st);


        HbaseUtil hbaseAddUtil = new HbaseUtil();
        String obj_value = "";
        try {

            obj_value = hbaseAddUtil.insertinfo("niit01", "2181", "Student", studentArrayList);
        } catch (Exception e) {
            e.printStackTrace();
        }


        resp.setContentType("text/html;charset=utf-8");
        PrintWriter pw = resp.getWriter();
        pw.write("<h1>" + obj_value);

    }

    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        doGet(req, resp);
    }
}





